package com.huike.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.huike.dto.TallyChannelDto;
import com.huike.dto.TallyDto;
import com.huike.dto.domain.Course;
import com.huike.dto.domain.Tally;
import com.huike.mapper.ContractMapper;
import com.huike.mapper.TallyMapper;
import com.huike.mapper.TbBusinessMapper;
import com.huike.mapper.TbClueMapper;
import com.huike.pojo.BusinessOpportunity;
import com.huike.service.TallyService;
import com.huike.vo.TallyCustomerVO;
import com.huike.vo.VulnerabilityMapVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class TallyServiceImpl extends ServiceImpl<TallyMapper, Tally> implements TallyService
{

    @Autowired
    private TallyMapper tallyMapper;

    @Autowired
    private TbClueMapper clueMapper;

    @Autowired
    private TbBusinessMapper businessMapper;

    @Autowired
    private ContractMapper contractMapper;

    /**
     * 客户统计-分页
     * @param tally
     * @return
     */
    @Override
    public List<Tally> contractStatisticsList(Tally tally)
    {
        return tallyMapper.contractStatisticsList(tally) ;
    }

    /**
     * 客户统计-部门查询分页
     * @return
     */
    @Override
    public List<Course> listSelect()
    {
        return tallyMapper.listSelect();
    }

    /**
     * 部门统计-分页接口
     * @param tallyDto
     * @return
     */
    @Override
    public List<TallyDto> deptStatisticsList(TallyDto tallyDto) {
        return tallyMapper.deptStatisticsList(tallyDto);
    }

    /**
     * 线索统计-分页接口
     * @param tallyDto
     * @return
     */
    @Override
    public List<TallyDto> cluesStatisticsList(TallyDto tallyDto) {
        return tallyMapper.cluesStatisticsList(tallyDto);
    }

    /**
     * 渠道统计-分页接口
     * @param tallyChannelDto
     * @return
     */
    @Override
    public List<TallyChannelDto> activityStatisticsList(TallyChannelDto tallyChannelDto) {
        return tallyMapper.activityStatisticsList(tallyChannelDto);
    }

    @Override
    public VulnerabilityMapVo getVulnerabilityMap(String beginCreateTime, String endCreateTime) {
        VulnerabilityMapVo vo =new VulnerabilityMapVo();
        //线索数
        vo.setCluesNums(clueMapper.countAllClues(beginCreateTime,endCreateTime));
        //有效线索数
        vo.setEffectiveCluesNums(clueMapper.effectiveCluesNums(beginCreateTime,endCreateTime));
        //商机数
        vo.setBusinessNums(businessMapper.businessNumsFromClue(beginCreateTime,endCreateTime));
        //合同数
       vo.setContractNums(contractMapper.contractNumsFromBusiness(beginCreateTime,endCreateTime));
        return vo;
    }

    @Override
    public TallyCustomerVO contractStatistics(String beginCreateTime, String endCreateTime) {
        TallyCustomerVO vo = new TallyCustomerVO();
        ArrayList<String> list = new ArrayList<>();
        // 使用Collections.addAll方法正确填充日期列表
        Collections.addAll(list, "2025-05-30", "2025-05-31", "2025-06-01", "2025-06-02", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06");
        vo.setxAxis(list);

        // 模拟新增客户数和客户总数的数据
        List<Integer> newCustomerData = Arrays.asList(5, 6, 2, 3, 1, 2, 4, 4);
        List<Integer> totalCustomerData = Arrays.asList(5, 6, 2, 3, 1, 2, 4, 4);

        // 构建返回的数据结构
        List<TallyCustomerVO.Series> series = new ArrayList<>();

        TallyCustomerVO.Series newCustomerSeries = new TallyCustomerVO.Series();
        newCustomerSeries.setName("新增客户数");
        newCustomerSeries.setData(newCustomerData);
        series.add(newCustomerSeries);

        TallyCustomerVO.Series totalCustomerSeries = new TallyCustomerVO.Series();
        totalCustomerSeries.setName("客户总数");
        totalCustomerSeries.setData(totalCustomerData);
        series.add(totalCustomerSeries);

        vo.setSeries(series);

        return vo;
    }

    @Override
    public TallyCustomerVO salesStatistics(String beginCreateTime, String endCreateTime) {
        TallyCustomerVO vo = new TallyCustomerVO();
        ArrayList<String> list = new ArrayList<>();
        // 使用Collections.addAll方法正确填充日期列表
        Collections.addAll(list, "2025-05-30", "2025-05-31", "2025-06-01", "2025-06-02", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06");
        vo.setxAxis(list);

        // 模拟新增客户数和客户总数的数据
        List<Integer> newCustomerData = Arrays.asList(2, 2, 3, 9, 10, 2, 4, 4);

        // 构建返回的数据结构
        List<TallyCustomerVO.Series> series = new ArrayList<>();

        TallyCustomerVO.Series newCustomerSeries = new TallyCustomerVO.Series();
        newCustomerSeries.setName("销售统计");
        newCustomerSeries.setData(newCustomerData);
        series.add(newCustomerSeries);

        vo.setSeries(series);

        return vo;
    }
    @Override
    public TallyCustomerVO cluesStatistics(String beginCreateTime, String endCreateTime) {
        TallyCustomerVO vo = new TallyCustomerVO();
        ArrayList<String> list = new ArrayList<>();
        // 使用Collections.addAll方法正确填充日期列表
        Collections.addAll(list, "2025-05-30", "2025-05-31", "2025-06-01", "2025-06-02", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06");
        vo.setxAxis(list);

        // 模拟新增客户数和客户总数的数据
        List<Integer> newCustomerData = Arrays.asList(8, 7, 2, 3, 0, 2, 4, 6);
        List<Integer> totalCustomerData = Arrays.asList(8, 7, 2, 3, 0, 2, 4, 6);

        // 构建返回的数据结构
        List<TallyCustomerVO.Series> series = new ArrayList<>();

        TallyCustomerVO.Series newCustomerSeries = new TallyCustomerVO.Series();
        newCustomerSeries.setName("新增线索数量");
        newCustomerSeries.setData(newCustomerData);
        series.add(newCustomerSeries);

        TallyCustomerVO.Series totalCustomerSeries = new TallyCustomerVO.Series();
        totalCustomerSeries.setName("线索总数量");
        totalCustomerSeries.setData(totalCustomerData);
        series.add(totalCustomerSeries);

        vo.setSeries(series);

        return vo;
    }
    @Override
    public TallyCustomerVO chanelStatistics(String beginCreateTime, String endCreateTime) {
        TallyCustomerVO vo = new TallyCustomerVO();
        ArrayList<String> list = new ArrayList<>();
        // 使用Collections.addAll方法正确填充日期列表
        Collections.addAll(list, "");
        vo.setxAxis(list);

        // 模拟新增客户数和客户总数的数据
        List<Integer> newCustomerData = Arrays.asList();
        List<Integer> totalCustomerData = Arrays.asList();

        // 构建返回的数据结构
        List<TallyCustomerVO.Series> series = new ArrayList<>();

        TallyCustomerVO.Series newCustomerSeries = new TallyCustomerVO.Series();
        newCustomerSeries.setName("新增线索数量");
        newCustomerSeries.setData(newCustomerData);
        series.add(newCustomerSeries);

        TallyCustomerVO.Series totalCustomerSeries = new TallyCustomerVO.Series();
        totalCustomerSeries.setName("线索总数量");
        totalCustomerSeries.setData(totalCustomerData);
        series.add(totalCustomerSeries);

        vo.setSeries(series);

        return vo;
    }@Override
    public TallyCustomerVO activityStatistics(String beginCreateTime, String endCreateTime) {
        TallyCustomerVO vo = new TallyCustomerVO();
        ArrayList<String> list = new ArrayList<>();
        // 使用Collections.addAll方法正确填充日期列表
        Collections.addAll(list, "");
        vo.setxAxis(list);

        // 模拟新增客户数和客户总数的数据
        List<Integer> newCustomerData = Arrays.asList();
        List<Integer> totalCustomerData = Arrays.asList();

        // 构建返回的数据结构
        List<TallyCustomerVO.Series> series = new ArrayList<>();

        TallyCustomerVO.Series newCustomerSeries = new TallyCustomerVO.Series();
        newCustomerSeries.setName("新增线索数量");
        newCustomerSeries.setData(newCustomerData);
        series.add(newCustomerSeries);

        TallyCustomerVO.Series totalCustomerSeries = new TallyCustomerVO.Series();
        totalCustomerSeries.setName("线索总数量");
        totalCustomerSeries.setData(totalCustomerData);
        series.add(totalCustomerSeries);

        vo.setSeries(series);

        return vo;
    }

}

